// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Core;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using Elastic.Transport;
using System;
using System.Runtime.Serialization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.QueryRules;

[JsonConverter(typeof(QueryRuleCriteriaTypeConverter))]
public enum QueryRuleCriteriaType
{
	[EnumMember(Value = "suffix")]
	Suffix,
	[EnumMember(Value = "prefix")]
	Prefix,
	[EnumMember(Value = "lte")]
	Lte,
	[EnumMember(Value = "lt")]
	Lt,
	[EnumMember(Value = "gte")]
	Gte,
	[EnumMember(Value = "gt")]
	Gt,
	[EnumMember(Value = "global")]
	Global,
	[EnumMember(Value = "fuzzy")]
	Fuzzy,
	[EnumMember(Value = "exact_fuzzy")]
	ExactFuzzy,
	[EnumMember(Value = "exact")]
	Exact,
	[EnumMember(Value = "contains")]
	Contains,
	[EnumMember(Value = "always")]
	Always
}

internal sealed class QueryRuleCriteriaTypeConverter : JsonConverter<QueryRuleCriteriaType>
{
	public override QueryRuleCriteriaType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		var enumString = reader.GetString();
		switch (enumString)
		{
			case "suffix":
				return QueryRuleCriteriaType.Suffix;
			case "prefix":
				return QueryRuleCriteriaType.Prefix;
			case "lte":
				return QueryRuleCriteriaType.Lte;
			case "lt":
				return QueryRuleCriteriaType.Lt;
			case "gte":
				return QueryRuleCriteriaType.Gte;
			case "gt":
				return QueryRuleCriteriaType.Gt;
			case "global":
				return QueryRuleCriteriaType.Global;
			case "fuzzy":
				return QueryRuleCriteriaType.Fuzzy;
			case "exact_fuzzy":
				return QueryRuleCriteriaType.ExactFuzzy;
			case "exact":
				return QueryRuleCriteriaType.Exact;
			case "contains":
				return QueryRuleCriteriaType.Contains;
			case "always":
				return QueryRuleCriteriaType.Always;
		}

		ThrowHelper.ThrowJsonException();
		return default;
	}

	public override void Write(Utf8JsonWriter writer, QueryRuleCriteriaType value, JsonSerializerOptions options)
	{
		switch (value)
		{
			case QueryRuleCriteriaType.Suffix:
				writer.WriteStringValue("suffix");
				return;
			case QueryRuleCriteriaType.Prefix:
				writer.WriteStringValue("prefix");
				return;
			case QueryRuleCriteriaType.Lte:
				writer.WriteStringValue("lte");
				return;
			case QueryRuleCriteriaType.Lt:
				writer.WriteStringValue("lt");
				return;
			case QueryRuleCriteriaType.Gte:
				writer.WriteStringValue("gte");
				return;
			case QueryRuleCriteriaType.Gt:
				writer.WriteStringValue("gt");
				return;
			case QueryRuleCriteriaType.Global:
				writer.WriteStringValue("global");
				return;
			case QueryRuleCriteriaType.Fuzzy:
				writer.WriteStringValue("fuzzy");
				return;
			case QueryRuleCriteriaType.ExactFuzzy:
				writer.WriteStringValue("exact_fuzzy");
				return;
			case QueryRuleCriteriaType.Exact:
				writer.WriteStringValue("exact");
				return;
			case QueryRuleCriteriaType.Contains:
				writer.WriteStringValue("contains");
				return;
			case QueryRuleCriteriaType.Always:
				writer.WriteStringValue("always");
				return;
		}

		writer.WriteNullValue();
	}
}

[JsonConverter(typeof(QueryRuleTypeConverter))]
public enum QueryRuleType
{
	[EnumMember(Value = "pinned")]
	Pinned,
	[EnumMember(Value = "exclude")]
	Exclude
}

internal sealed class QueryRuleTypeConverter : JsonConverter<QueryRuleType>
{
	public override QueryRuleType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		var enumString = reader.GetString();
		switch (enumString)
		{
			case "pinned":
				return QueryRuleType.Pinned;
			case "exclude":
				return QueryRuleType.Exclude;
		}

		ThrowHelper.ThrowJsonException();
		return default;
	}

	public override void Write(Utf8JsonWriter writer, QueryRuleType value, JsonSerializerOptions options)
	{
		switch (value)
		{
			case QueryRuleType.Pinned:
				writer.WriteStringValue("pinned");
				return;
			case QueryRuleType.Exclude:
				writer.WriteStringValue("exclude");
				return;
		}

		writer.WriteNullValue();
	}
}